package com.qf.entity;

import com.qf.pojo.CheckNull;
import com.qf.pojo.CheckType;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * sys_category
 *
 * @author
 */
public class SysCategory implements Serializable, CheckNull {
    private Integer cId;

    /**
     * 下行命令显示名字
     */
    private String commandName;

    /**
     * 更新者
     */
    private String updateBy;

    /**
     * 更新时间
     */
    private Date updateTime;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 上行数据
     */
    private String rxCommand;

    /**
     * 创建者
     */
    private String createBy;

    /**
     * 1 有效 0 无效
     */
    private Short status;

    /**
     * 下行数据
     */
    private String txCommand;

    /**
     * 分类名字
     */
    private String categoryName;

    private static final long serialVersionUID = 1L;


    @Override
    public boolean isEmpty(CheckType type) {
        switch (type) {
            case ADD: //添加的时候 大部分数据都可以为空,唯独分类的名字和有效性不能为空
                return !StringUtils.hasText(categoryName);
            case UPDATE:
                return (ObjectUtils.isEmpty(cId) || cId <= 0) ||
                        (!StringUtils.hasText(categoryName)
                                && !StringUtils.hasText(txCommand)
                                && !StringUtils.hasText(rxCommand)
                                && !StringUtils.hasText(commandName)
                                && (ObjectUtils.isEmpty(status) || status < 0));
            default:
                break;
        }
        return CheckNull.super.isEmpty(type);
    }

    public Integer getcId() {
        return cId;
    }

    public void setcId(Integer cId) {
        this.cId = cId;
    }

    public String getCommandName() {
        return commandName;
    }

    public void setCommandName(String commandName) {
        this.commandName = commandName;
    }

    public String getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(String updateBy) {
        this.updateBy = updateBy;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getRxCommand() {
        return rxCommand;
    }

    public void setRxCommand(String rxCommand) {
        this.rxCommand = rxCommand;
    }

    public String getCreateBy() {
        return createBy;
    }

    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    public Short getStatus() {
        return status;
    }

    public void setStatus(Short status) {
        this.status = status;
    }

    public String getTxCommand() {
        return txCommand;
    }

    public void setTxCommand(String txCommand) {
        this.txCommand = txCommand;
    }

    public String getCategoryName() {
        return categoryName;
    }

    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        SysCategory other = (SysCategory) that;
        return (this.getcId() == null ? other.getcId() == null : this.getcId().equals(other.getcId()))
                && (this.getCommandName() == null ? other.getCommandName() == null : this.getCommandName().equals(other.getCommandName()))
                && (this.getUpdateBy() == null ? other.getUpdateBy() == null : this.getUpdateBy().equals(other.getUpdateBy()))
                && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
                && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
                && (this.getRxCommand() == null ? other.getRxCommand() == null : this.getRxCommand().equals(other.getRxCommand()))
                && (this.getCreateBy() == null ? other.getCreateBy() == null : this.getCreateBy().equals(other.getCreateBy()))
                && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
                && (this.getTxCommand() == null ? other.getTxCommand() == null : this.getTxCommand().equals(other.getTxCommand()))
                && (this.getCategoryName() == null ? other.getCategoryName() == null : this.getCategoryName().equals(other.getCategoryName()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getcId() == null) ? 0 : getcId().hashCode());
        result = prime * result + ((getCommandName() == null) ? 0 : getCommandName().hashCode());
        result = prime * result + ((getUpdateBy() == null) ? 0 : getUpdateBy().hashCode());
        result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
        result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
        result = prime * result + ((getRxCommand() == null) ? 0 : getRxCommand().hashCode());
        result = prime * result + ((getCreateBy() == null) ? 0 : getCreateBy().hashCode());
        result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
        result = prime * result + ((getTxCommand() == null) ? 0 : getTxCommand().hashCode());
        result = prime * result + ((getCategoryName() == null) ? 0 : getCategoryName().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", cId=").append(cId);
        sb.append(", commandName=").append(commandName);
        sb.append(", updateBy=").append(updateBy);
        sb.append(", updateTime=").append(updateTime);
        sb.append(", createTime=").append(createTime);
        sb.append(", rxCommand=").append(rxCommand);
        sb.append(", createBy=").append(createBy);
        sb.append(", status=").append(status);
        sb.append(", txCommand=").append(txCommand);
        sb.append(", categoryName=").append(categoryName);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}
